<template>
  <div class="box">
    <!-- 头部 -->
    <div class="box-hd">
      <h2 class="title-div">
        审批设置
        <div class="fr">
          <el-button type="primary" size="small" @click="dialogAdd=true">新增</el-button>
        </div>
      </h2>
    </div>
    <!-- 内容区 -->
    <el-row class="box-bd">
      <el-col :span="6" class="left-side">
        <h3 class="side-hd">类型</h3>
        <div class="side-list">
          <ul>
            <li v-for="(item,index) in typeList" :key="index">
              <span>{{ item.typeName }}</span>
              <el-link
                type="info"
                v-show="btnState"
                :underline="false"
                class="btn-link"
                @click="typeDel(item)"
              >
                <i class="el-icon-delete"></i>
              </el-link>
              <el-link
                type="info"
                v-show="btnState"
                :underline="false"
                class="btn-link"
                @click="typeEdit(item)"
              >
                <i class="el-icon-edit"></i>
              </el-link>
            </li>
          </ul>
          <div class="add-box" v-show="btnState">
            <el-link type="primary" @click="typeDialogAdd = true" :underline="false">新增类型</el-link>
          </div>
        </div>
        <div class="btn-box">
          <el-link type="primary" v-show="!btnState" @click="btnState=true" :underline="false">编辑</el-link>
          <el-link type="primary" v-show="btnState" @click="btnState=false" :underline="false">完成</el-link>
        </div>
      </el-col>
      <el-col :span="18" class="p30"></el-col>
    </el-row>
    <!-- 新增 -->
    <el-dialog
      title="新增类别"
      :visible.sync="typeDialogAdd"
      @closed="formReset"
      :close-on-click-modal="false"
    >
      <el-form :model="typeForm" ref="typeForm">
        <el-form-item label="类别名称" :label-width="formLabelWidth">
          <el-input v-model="typeForm.typeName" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="typeDialogAdd = false">取 消</el-button>
        <el-button type="primary" @click="typeSave">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 编辑 -->
    <el-dialog
      title="编辑类别"
      :visible.sync="typeDialogEdit"
      @closed="formReset"
      :close-on-click-modal="false"
    >
      <el-form :model="typeForm" ref="typeForm">
        <el-form-item label="角色名称" :label-width="formLabelWidth">
          <el-input v-model="typeForm.typeName" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="typeDialogEdit = false">取 消</el-button>
        <el-button type="primary" @click="typeUpdate">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
export default {
  data() {
    return {
      btnState: false,
      formLabelWidth: '120px',
      companyId: this.$store.state.user.companyId,
      dialogEdit: false,
      dialogAdd: false,
      typeDialogEdit: false,
      typeDialogAdd: false,
      typeList: [],
      typeForm: {
        id: '',
        companyId: this.$store.state.user.companyId,
        typeName: ''
      }
    }
  },
  mounted() {},
  methods: {
    typeSave() {
      // roleSave(this.roleForm).then(res => {
      //   if (res.success) {
      //     this.$message.success(res.message)
      //     this.roleDialogAdd = false
      //     this.initRoleList()
      //   } else {
      //     this.$message.error(res.message)
      //   }
      // })
    },
    typeEdit(row) {
      this.typeForm = row
      this.typeDialogEdit = true
    },
    typeUpdate() {
      // roleUpdate(this.roleForm).then(res => {
      //   if (res.success) {
      //     this.$message.success(res.message)
      //     this.roleDialogEdit = false
      //     this.initRoleList()
      //   } else {
      //     this.$message.error(res.message)
      //   }
      // })
    },
    typeDel(row) {
      // roleDel(row).then(res => {
      //   if (res.success) {
      //     this.$message.success(res.message)
      //     this.initRoleList()
      //   } else {
      //     this.$message.error(res.message)
      //   }
      // })
    },
    formReset() {
      this.typeForm.id = ''
      this.typeForm.typeName = ''
    }
  }
}
</script>
<style lang="scss" scoped>
.hd-title {
  color: #909399;
  font-size: 14px;
  height: 35px;
}
.box-bd {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  top: 68px;
  .side-bar {
    padding: 25px;
  }
  .table-list {
    margin-bottom: 15px;
  }
  .list-box {
    li {
      height: 30px;
      line-height: 30px;
    }
  }
}
.left-side {
  position: relative;
  height: 100%;
  border-right: 1px solid #e4eaf0;
  .add-box {
    height: 50px;
    line-height: 50px;
    text-align: center;
  }
  .side-hd {
    height: 35px;
    line-height: 36px;
    color: #909399;
    padding: 0 24px;
    font-size: 14px;
  }
  .btn-box {
    @extend .add-box;
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    border-top: 1px solid #e4eaf0;
  }
  .side-list {
    height: calc(100% - 85px);
    overflow-y: auto;
    li {
      height: 50px;
      line-height: 50px;
      padding: 0 35px;
      &:hover {
        background: #f0f3f5;
        color: #359cf3;
      }
      .btn-link {
        float: right;
        margin-left: 15px;
      }
    }
  }
}
</style>
